package com.coolingme.threadlocal06;

/**
 * ThreadLocal单例测试
 *
 * @author wangyue
 * @date 2020/9/29 16:44
 */
public class Test {

    public static void main(String[] args) {
        // 在main线程中，所有的实例都是一样的
        // 只能确保每个线程中是唯一的
        System.out.println(ThreadLocalSingleton.getInstance());
        System.out.println(ThreadLocalSingleton.getInstance());
        System.out.println(ThreadLocalSingleton.getInstance());
        System.out.println(ThreadLocalSingleton.getInstance());
        System.out.println(ThreadLocalSingleton.getInstance());


        new Thread(() -> {
            System.out.println("-----------------------------");
            System.out.println(ThreadLocalSingleton.getInstance());
            System.out.println(ThreadLocalSingleton.getInstance());
            System.out.println("-----------------------------");
        }).start();

        new Thread(() -> System.out.println(ThreadLocalSingleton.getInstance())).start();

    }

}
